<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/21
 * Time: 9:59
 */

namespace app\index\controller;


use think\Db;

class News
{
    public function add()
    {
        return view();
//        return "欢迎使用新闻添加功能！";
    }

    public function delete()
    {
        return "你好！";
    }

    /**
     * 添加新闻
     */
    public function save($title,$content,$newsType)
    {
        $data = ["title"=>$title,"content"=>$content,"newsType"=>$newsType];
//        Db::table("zy_news")->insert($data);
        $id = Db::name("news")->insertGetId($data);
        if($id){
            echo "添加成功!最新编号为：" . $id;
        }else {
            echo "添加失败!";
        }
    }

    public function update($title=null, $newsid=null)
    {
        //Index.php/index/news/update?title=新的标语&newsid=19
        $model = db("news");
        $r = $model->where("id", $newsid)->update(["title"=>$title]);
        //输出执行的sql语句
        echo $model->getLastSql();
        if($r){
            echo "<br>";
            echo "更新成功！";
        }else {
            echo "<br>";
            echo "更新失败！";
        }
    }
}


